#include <iostream>
#include "simpletree.h"

using namespace std;

template<class T>
void SimpleTree::insert(Node<T>* pNode)
{
    Node<T> *current = _root;
    Node<T> *parent = _root;
    if (_root == NULL) {
        _root = pNode;
    }
    else {
        
        // move
        while(current != NULL) {
            if (*pNode >= *current) {
                parent = current;
                current = current->right();
            }
            else {
                parent = current;
                current = current->left();
            }
        }

        // put
        if (*parent >= *pNode) {
            parent->setRight(pNode);
            parent->setParent(parent);
        } 
        else {
            parent->setLeft(pNode);
            parent->setParent(parent);
        }
    }
}

template<class T>
Node<T>* SimpleTree::find(Node<T>* pNode)
{
    Node<T> *current = _root, *parent = _root;
    while(current != NULL) {
        if (*pNode > *current) {
            current = current->right();
        }
        else if (*pNode < *current) {
            current = current->left();
        }
        else {
            return current;
        }
    }
    return NULL;
}

template<class T>
Node<T>* SimpleTree::remove(Node<T>* pNode)
{
}
